package com.lovo.practice_7_7;

import org.w3c.dom.ls.LSResourceResolver;

import javax.sql.rowset.FilteredRowSet;
import javax.xml.transform.Source;
import java.io.InterruptedIOException;
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Locale;

public class J189_7_7 {

    //编写一个函数，实现日期格式化处理
    public void method1() {

        LocalDate nowDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        String format = nowDate.format(formatter);
        System.out.println(format);


    }

    //编写一个函数，将驼峰单词转换为蛇形单词：CamelCase变成Snake_Case
    public String method2(String str) {
        char[] strChar = str.toCharArray();
//        System.out.println(strChar);
        for (int i = 1; i < strChar.length; i++) {
            if (strChar[i] >= 65 && strChar[i] <= 90) {
                char[] strnewChar = new char[strChar.length + 1];
                for (int j = 0; j < strnewChar.length; j++) {
                    if (j < i) {
                        strnewChar[j] = strChar[j];
                    }
                    if (j == i) {
                        strnewChar[j] = '_';
                    }
                    if (j > i) {
                        strnewChar[j] = strChar[j - 1];
                    }
                }
                strChar = strnewChar;
                i++;
            }
        }
//        System.out.println(strChar);
        str = String.valueOf(strChar);
        return str.toLowerCase();
    }

    //编写一个函数，将蛇形命名法的单词转换为驼峰命名法：my_name变成myName；
    public String method3(String str) {
        String lastStr = "";
        String[] s = str.split("_");
//        System.out.println(Arrays.toString(s));
        for (int i = 1; i < s.length; i++) {
            s[i] = s[i].substring(0, 1).toUpperCase(Locale.ROOT) + s[i].substring(1);
        }
//        System.out.println(Arrays.toString(s));
        for (String m : s) {
            lastStr += m;
        }
        return lastStr;
    }

    //编写一个函数，将货币数字以千分位方式表示
    public String method4(String str) {
        String lastStr = "";
        String s = str.substring(0, str.indexOf("."));//1234567
        String s0 = str.substring(str.indexOf("."));//.03
        int x = s.length() % 3;
        String s1 = s.substring(0, x);//1
        if (s.length() % 3 != 0) {
            s1 = s1 + ",";
        }

        String s2 = s.substring(x);//234567
        String[] s3 = s2.split("");//2,3,4,5,6,7
        for (int i = 0; i < s3.length; i++) {
            if ((i + 1) % 3 == 0) {
                if (i + 2 > s3.length) {
                    continue;
                } else {
                    s3[i] += ",";
                }

            }
        }
        for (String m : s3) {
            lastStr += m;
        }
        return s1 + lastStr + s0;
    }

    public static void main(String[] args) {
//  测试方法2     String str = "MyNameHappy";
//        J189_7_7 a = new J189_7_7();
//        System.out.println(a.method2(str));
//     测试方法3   String str = "my_name_happy";
//        System.out.println(str);
//        J189_7_7 a = new J189_7_7();
//        System.out.println(a.method3(str));
//      测试方法4  String str = "1234561.03";
//        System.out.println(str);
//        J189_7_7 a = new J189_7_7();
//        System.out.println(a.method4(str));
    }
}
